//go:build windows
// +build windows

package lscpu

import (
	"github.com/shirou/gopsutil/v3/cpu"
	"regexp"
	"strconv"
)

func GetCPUInfo() (*CPUInfo, error) {
	info, err := cpu.Info()
	if err != nil {
		return nil, err
	}
	ci := &CPUInfo{
		Num: len(info),
	}
	for _, c := range info {
		// ci.Core += int(c.Cores)
		ci.Processor += int(c.Cores)
		ci.ModelName = c.ModelName
		ci.Vendor = c.VendorID
	}
	// 根据 @ 分割cpu频率
	re := regexp.MustCompile(`@ (.+)`)
	matches := re.FindStringSubmatch(ci.ModelName)
	if len(matches) < 2 {
		info, err := cpu.Info()
		if err != nil {
			return nil, err
		}
		float := strconv.FormatFloat(info[0].Mhz, 'f', 2, 64)
		ci.Speed = float + " MHz"
	} else {
		ci.Speed = matches[1]
	}
	return ci, nil
}
